# Maintainer(Arch): Robin Broda <robin@broda.me>
# Contributor: Pierre Neidhardt <ambrevar@gmail.com>
# Contributor: Sergej Pupykin <pupykin.s+arch@gmail.com>
# Contributor: Gergely Imreh <imrehgATgmailDOTcom>
# Contributor: dschauer <dschauerATgmailDOTcom>
# Contributor: Stefan Husmann <stefan-husmann@t-online.de>
# Contributor: Jeremy Cowgar <jeremy@cowgar.com>
# Maintainer: Sagar Acharya <sagaracharya@tutanota.com>

pkgname=tcc
pkgver=0.9.27
pkgrel=1
pkgdesc="Tiny C Compiler"
arch=('x86_64' 'i686')
url="https://bellard.org/tcc/"
license=('LGPL-2.1')
depends=('glibc')
options=('docs' 'staticlibs')
source=("https://download.savannah.nongnu.org/releases/tinycc/${pkgname}-${pkgver}.tar.bz2"
		"series"
		"0001-Disable-test-not-working-on-i386.patch"
		"0002-Disable-stack-protector-in-runtime-library.patch"
		"0003-Prevent-dead-code-on-x86-in-prepare_dynamic_rel.patch")
sha512sums=('835184292d97c07f0ff7b36ec550e855e649b04e23c7e2a1c706d223409eb60708dc1ae969f28eba45e56c8b96ae56936b93caf9d8a13ac5adf119014d5367a7'
            '431435befa6010d485dbfd4890f5c3fee7331993738c5d71d1cd2ee333fee24bc85f387df2faed02cb78841b019434ad3a7af20541346d45e731eb022d896a9c'
            'e81367441b536d0d072ff8bab92ffb961a23ee5377e138be89cd64c79d152b9a2ceb1785daa10e0d3e25ea33496f30e4dd265b73ad90efd72fead2b767c85c2c'
            '14ec408523ddd8238c1e1b84c597d831d9f5b2454ce44c3c4d1eebfe4ecea5c4acc6909977ea40d9665bd3699c6c3a92efd27352a349b75d4190e33e392b794c'
            '8b0f9e8aa013110b2d5a5aec72b017aca124e12952135f280c74649debb52f505427cb40cb95ef9cef8904fda23ca7a3ff9b706c853ee493f2b0a105abdca4f1')

prepare() {
  cd ${pkgname}-${pkgver}

  mkdir ./patches
  cp ${srcdir}/series ./patches
  cp ${srcdir}/*.patch ./patches

  export QUILT_PATCHES=patches
  export QUILT_REFRESH_ARGS='-p ab --no-timestamps --no-index'
  export QUILT_DIFF_ARGS='--no-timestamps'

  quilt push -av

}

build() {
  cd ${pkgname}-${pkgver}
  unset CFLAGS
  unset LDFLAGS
  ./configure --prefix=/usr
  make
}

package() {
  cd ${pkgname}-${pkgver}

 make DESTDIR="$pkgdir" docdir="$pkgdir"/usr/share/doc/tcc install

 make clean
 make CFLAGS="-fPIC"
 gcc -shared -o libtcc.so *.o
 install -Dm755 libtcc.so -t "${pkgdir}/usr/lib/"
}
